package cn.com.css.taxInspection.common.sysjob.service;

import cn.com.css.taxInspection.common.constants.Constants;
import cn.com.css.taxInspection.common.sysjob.utils.LogUtils;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

@Service
public class ClearDsrwBusinessService {

    private static final Logger logger = LoggerFactory.getLogger(ClearDsrwBusinessService.class);
    private final JdbcTemplate jdbcTemplate; // 使用 final 关键字确保依赖是不可变的
    private final LogUtils logUtils;

    @Autowired
    public ClearDsrwBusinessService(JdbcTemplate jdbcTemplate, LogUtils logUtils) {
        this.jdbcTemplate = jdbcTemplate;  // 通过构造器注入 JdbcTemplate
        this.logUtils = logUtils;  // 通过构造器注入 JdbcTemplate
    }

    //关注查补定时任务方法
    public void checkSystemStatus() {
        // 每月清空一次日志表
        clearDsrwLog();
    }

    private void clearDsrwLog() {
        String tableName = "jc_dsrw_log";
        try {
            jdbcTemplate.execute("TRUNCATE TABLE kf_jicha_helper.jc_dsrw_log;"); // 使用 execute 执行 DROP TABLE
            logger.info("表 [{}] 创建成功", tableName);
            logUtils.saveDsrwLog("03", Constants.DSRW_DSRZLOG, Constants.DSRW_ZXCG, null, tableName);
        } catch (Exception e) {
            String errorMsg = String.format("错误信息: %s", e.getMessage());
            logger.info(errorMsg);
            logUtils.saveDsrwLog("03", Constants.DSRW_DSRZLOG, Constants.DSRW_ZXSB, errorMsg, tableName);
        }
    }

}
